﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SGTD.Entidades;

namespace SGTD.DAO
{
    public class clsAreaDAO
    {
        public List<clsArea> ListarArea()
        {

            SqlCommand objcmd = new SqlCommand("Areas_Listar_PA");

            objcmd.CommandType = System.Data.CommandType.StoredProcedure;
            objcmd.Connection = clsConexion.ObtenerConexion();
            List<clsArea> objListaArea = new List<clsArea>();
            try
            {
                SqlDataReader objDr = objcmd.ExecuteReader();
                if (objDr.HasRows)
                {
                    while (objDr.Read())
                    {
                        clsArea objArea = new clsArea();

                        objArea.IdArea = Convert.ToInt32(objDr["IdArea"]);
                        objArea.NombreArea = Convert.ToString(objDr["NombreArea"]);
                        //objArea.Jefe.IdEmpleado = Convert.ToInt32(objDr["IdEmpleado"]);
                        objArea.Estado = Convert.ToBoolean(objDr["Estado"]);
                         

                        objListaArea.Add(objArea);
                    }
                    objDr.Close();
                }
            }
            catch (SqlException sql) { throw sql; }

            finally
            {
                objcmd.Connection.Close();
            }

            return objListaArea;
        }
    }
}
